using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Wzh_CheckAB
{
    public class TextAsset_Dic : IDataDic
    {
        public List<ItemDataBase> Datalist => null;
        private List<TextAsset> datalist = new List<TextAsset>();
        private List<int> dataIDlist = new List<int>();
        private Dictionary<int, TextAsset> dataDic;
        private string name;
        public TextAsset_Dic(string name, Dictionary<int, TextAsset> dataDic)
        {
            this.name = name;
            this.dataDic = dataDic;
            datalist.AddRange(dataDic.Values);
            dataIDlist.AddRange(dataDic.Keys);
        }
        public int Count()
        {
            return dataDic.Count;
        }

        public string TName()
        {
            return name;
        }
        public object GetData(int index)
        {
            return datalist[index];
        }

        public int GetDateID(int index)
        {
            return dataIDlist[index];
        }

        public string GetDateName(int index)
        {
            if (datalist == null) return "";
            var data = datalist[index];
            if (data==null) return "";
            return datalist[index].name;
        }

        public GameObject Show3D(ItemDataBase data)
        {
            var pbdata = data as PrefabData;
            if (pbdata == null) return null;
            return AssetBundleLoader.LoadAndInstantiate<GameObject>(pbdata.assetbundleDir, pbdata.assetbundleName, pbdata.prefab);
        }
    }
}